#include <string>
using namespace std;
/*
 * @lc app=leetcode.cn id=168 lang=cpp
 *
 * [168] Excel表列名称
 */

// @lc code=start
class Solution {
public:
    string convertToTitle(int columnNumber) {
        if (columnNumber < 27) {
            string res; res.push_back('A' + columnNumber - 1);
            return res;
        }
        char x; int mod = 26;
        if (columnNumber % 26 == 0) {
            x = 'Z';
            mod = 27;
        } else {
            x = columnNumber % 26 - 1 + 'A';
        }
        string now = convertToTitle(columnNumber / mod);
        now.push_back(x);
        return now;
    }
};
// @lc code=end

